package com.youyi.yyviewsdklibrary.View;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lkx.liandianqinew.R;

public class TitleBarView extends RelativeLayout {
    private ImageView mBack;
    private ImageView mIv_menu;
    private View mLine;
    private RelativeLayout mMain;
    private TextView mMenu;
    private TextView mTitle;
    private onItemClickListener onItemClickListener;

    public interface onItemClickListener {
        void onBackClick(View view);

        void onMenuClick(View view);

        void onTitleClick(View view);
    }

    public void setOnItemClickListener(onItemClickListener onitemclicklistener) {
        this.onItemClickListener = onitemclicklistener;
    }

    public TitleBarView(Context context) {
        super(context);
    }

    public TitleBarView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        int color = getResources().getColor(R.color.colorAccent);
        int color2 = getResources().getColor(R.color.white);
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, R.styleable.TitleBarView);
        int resourceId = obtainStyledAttributes.getResourceId(R.styleable.TitleBarView_iv_back, R.drawable.view_title_back);
        int resourceId2 = obtainStyledAttributes.getResourceId(R.styleable.TitleBarView_iv_menu, R.drawable.view_title_menu);
        String string = obtainStyledAttributes.getString(R.styleable.TitleBarView_tv_title);
        String string2 = obtainStyledAttributes.getString(R.styleable.TitleBarView_tv_menu);
        boolean z = obtainStyledAttributes.getBoolean(R.styleable.TitleBarView_show_iv_back, true);
        boolean z2 = obtainStyledAttributes.getBoolean(R.styleable.TitleBarView_show_iv_menu, false);
        boolean z3 = obtainStyledAttributes.getBoolean(R.styleable.TitleBarView_show_tv_menu, false);
        boolean z4 = obtainStyledAttributes.getBoolean(R.styleable.TitleBarView_show_line, false);
        int color3 = obtainStyledAttributes.getColor(R.styleable.TitleBarView_titlebar_bg, color);
        int color4 = obtainStyledAttributes.getColor(R.styleable.TitleBarView_text_color_title, color2);
        int color5 = obtainStyledAttributes.getColor(R.styleable.TitleBarView_text_color_menu, color2);
        View inflate = LayoutInflater.from(context).inflate(R.layout.view_title_bar_layout, (ViewGroup) this, true);
        this.mLine = inflate.findViewById(R.id.titlebar_id_line);
        this.mBack = (ImageView) inflate.findViewById(R.id.titlebar_btn_back);
        this.mIv_menu = (ImageView) inflate.findViewById(R.id.titlebar_iv_menu);
        this.mTitle = (TextView) inflate.findViewById(R.id.titlebar_tv_title);
        this.mMenu = (TextView) inflate.findViewById(R.id.titlebar_tv_menu);
        this.mMain = (RelativeLayout) inflate.findViewById(R.id.titlebar_id_main);
        this.mBack.setImageResource(resourceId);
        this.mIv_menu.setImageResource(resourceId2);
        this.mTitle.setText(string);
        this.mMenu.setText(string2);
        this.mBack.setVisibility(z ? View.VISIBLE : View.GONE);
        this.mLine.setVisibility(z4 ? View.VISIBLE : View.GONE);
        this.mIv_menu.setVisibility(z2 ? View.VISIBLE : View.GONE);
        this.mMenu.setVisibility(z3 ? View.VISIBLE : View.GONE);
        this.mMain.setBackgroundColor(color3);
        this.mTitle.setTextColor(color4);
        this.mMenu.setTextColor(color5);
        this.mTitle.setOnClickListener(new OnClickListener() {
            public void onClick(View view) {
                if (TitleBarView.this.onItemClickListener != null) {
                    TitleBarView.this.onItemClickListener.onTitleClick(view);
                }
            }
        });
        this.mBack.setOnClickListener(new OnClickListener() {
            /* class com.youyi.yyviewsdklibrary.View.TitleBarView.AnonymousClass2 */

            public void onClick(View view) {
                if (TitleBarView.this.onItemClickListener != null) {
                    TitleBarView.this.onItemClickListener.onBackClick(view);
                }
            }
        });
        this.mIv_menu.setOnClickListener(new OnClickListener() {
            /* class com.youyi.yyviewsdklibrary.View.TitleBarView.AnonymousClass3 */

            public void onClick(View view) {
                if (TitleBarView.this.onItemClickListener != null) {
                    TitleBarView.this.onItemClickListener.onMenuClick(view);
                }
            }
        });
        this.mMenu.setOnClickListener(new OnClickListener() {
            /* class com.youyi.yyviewsdklibrary.View.TitleBarView.AnonymousClass4 */

            public void onClick(View view) {
                if (TitleBarView.this.onItemClickListener != null) {
                    TitleBarView.this.onItemClickListener.onMenuClick(view);
                }
            }
        });
    }

    public void setImgBack(int i) {
        this.mBack.setImageResource(i);
    }

    public void setImgMenu(int i) {
        this.mIv_menu.setImageResource(i);
    }

    public void setTitle(String str) {
        this.mTitle.setText(str);
    }

    public void setMenu(String str) {
        this.mMenu.setText(str);
    }

    public void setBg(int i) {
        this.mMain.setBackgroundColor(i);
    }

    public void setTitleColor(int i) {
        this.mTitle.setTextColor(i);
    }

    public void setMenuColor(int i) {
        this.mMenu.setTextColor(i);
    }

    public void showTvMenu(Boolean bool) {
        this.mMenu.setVisibility(bool.booleanValue() ? View.VISIBLE : View.GONE);
    }

    public void showIvMenu(Boolean bool) {
        this.mIv_menu.setVisibility(bool.booleanValue() ? View.VISIBLE : View.GONE);
    }

    public void showLine(Boolean bool) {
        this.mLine.setVisibility(bool.booleanValue() ? View.VISIBLE : View.GONE);
    }

    public void showBack(Boolean bool) {
        this.mBack.setVisibility(bool.booleanValue() ? View.VISIBLE : View.GONE);
    }
}
